package com.base.caselib.print;

import android.content.Context;
import android.text.format.Time;

import com.base.caselib.EasyCasePrint;
import com.base.caselib.bean.Goods;
import com.base.caselib.bean.TempOraryBean;
import com.base.caselib.utils.ConvertNumber;
import com.base.caselib.utils.Utils;
import com.base.commonlib.base.BaseApp;
import com.base.commonlib.bean.EasyCaseModel;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.utils.DeteUtil;
import com.base.commonlib.utils.PrintUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by weikailiang on 2019/11/5.
 */

public class CasePrintUtil {
    public static void printEasyCase(Context context, final EasyCaseModel Easy){
        // TODO: 2018/12/15 联系电话
        PrintUtil.init(context, new PrintUtil.PrintRunnable() {
            @Override
            public void run() throws Exception {
                if (Easy.getPenaltyWay()==null){
                    Easy.setPenaltyWay("警告");
                }
                int[] normal = new int[]{PrintUtil.HIGHERX01};
                int[] normal_line = new int[]{PrintUtil.HIGHERX01, PrintUtil.UNDERLINE, PrintUtil.BOLD};
                Thread.sleep(1000);
                for (int i = 0; i < 2; i++) {
                    PrintUtil.printText("\n\n\n"+(Easy.getRootDeptName()==null?"":Easy.getRootDeptName())+"\n", new int[]{PrintUtil.HIGHERX2, PrintUtil.ALIGNMIDDLE});
                    PrintUtil.printText("行  政  处  罚  决  定  书\n", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                    PrintUtil.printText("                   (简易程序)\n", normal);
                    PrintUtil.printText("      编号：" + (Easy.getCaseNumber()==null?"":Easy.getCaseNumber()) + "\n", normal);
                    PrintUtil.printText("公民 ", normal);
                    PrintUtil.printText((Easy.getLitigantCitizenName()==null?"":Easy.getLitigantCitizenName()), normal);
                    PrintUtil.printText(" 性别 ", normal);
                    PrintUtil.printText((Easy.getLitigantCitizenGender()==null?"":Easy.getLitigantCitizenGender()), normal);
                    PrintUtil.printText(" 年龄 ", normal);
                    PrintUtil.printText((Easy.getLitigantCitizenAge()==null?"":Easy.getLitigantCitizenAge()), normal);
                    PrintUtil.printText(" 住址或单位 ", normal);
                    PrintUtil.printText((Easy.getLitigantCitizenAddress()==null?"":Easy.getLitigantCitizenAddress()), normal_line);
                    PrintUtil.printText("    现查明，当事人于 ", normal);
                    PrintUtil.printText((Easy.getOccurredTime()==null?"":Easy.getOccurredTime()), normal_line);
                    PrintUtil.printText(" 在  ", normal);
                    PrintUtil.printText((Easy.getOccurredAddress()==null?"":Easy.getOccurredAddress()), normal_line);
                    PrintUtil.printText(" 进行 ", normal);

                    //违法的行为，要根据行为的长度来判断下面的换行
                    String strLength = (Easy.getItemAct()==null?"":Easy.getItemAct());
                    PrintUtil.printText(strLength, normal_line);

                    PrintUtil.printText(" 行为，该行为违反了", normal);
                    PrintUtil.printText((Easy.getManagementBasis()==null?"":Easy.getManagementBasis()), normal_line);
                    PrintUtil.printText(" 的规定，现责令你立即改正。并依据 ", normal);
                    PrintUtil.printText((Easy.getLegalBasis()==null?"":Easy.getLegalBasis()), normal_line);
                    PrintUtil.printText("的规定，决定给予 ", normal);

                    if (Easy.getPenaltyWay().equals("警告")) {
                        PrintUtil.printText("警告", normal_line);
                        PrintUtil.printText(" 处罚。", normal);
                    } else if (Easy.getPenaltyWay().equals("罚款")) {
                        PrintUtil.printText(Easy.getPenaltyAmount(), normal_line);
                        PrintUtil.printText(" 元的行政处罚。", normal);
                    }
                    if (Easy.getMethodPenaltyPayment()==null){
                        Easy.setMethodPenaltyPayment("");
                    }
                    if (!Easy.getMethodPenaltyPayment().equals("")) {
                        PrintUtil.printText("\n    当事人应以以下方式履行处罚决定：", normal);
                        PrintUtil.printText((Easy.getMethodPenaltyPaymentValue()==null?"":Easy.getMethodPenaltyPaymentValue()), normal_line);
                    }
                    if (RealNetWorkUtil.TYPE.equals("0")){
                        PrintUtil.printText("如你（单位）不服本处罚决定，可以在接到本决定书之日起60日内向吴中区人民政府申请行政复议；也可以在6个月内直接向有管辖权的人民法院起诉，但不得停止执行本处罚决定。逾期不申请行政复议也不向人民法院起诉，又不履行本处罚决定的，根据《中华人民共和国行政处罚法》第五十一条第（三）项之规定，本机关将依法申请人民法院强制执行。复议或诉讼期间，本决定不停止执行。\n执法人员：", normal);
                    }else if (RealNetWorkUtil.TYPE.equals("1")){
                        PrintUtil.printText("如你（单位）不服本决定，可以在接到本决定书之日起六十日内向昆山市人民政府申请行政复议；也可以在六个月内直接向有管辖权的人民法院起诉。逾期不履行本处罚决定的，根据《中华人民共和国行政处罚法》第五十一条第（三）项的规定，本机关将依法申请人民法院强制执行。行政复议或行政诉讼期间，本处罚决定不停止执行。\n执法人员：", normal);
                    }

                    PrintUtil.printText((Easy.getParentName()==null?"":Easy.getParentName()), normal_line);
                    PrintUtil.printText("\n处罚地点: ", normal);
                    PrintUtil.printText((Easy.getOccurredAddress()==null?"":Easy.getOccurredAddress())+"\n", normal);
                    if (Easy.getPenaltyWay().equals("罚款")) {//=2 罚款   5元-124623041|10元-124623009,124623010
                        PrintUtil.printText("罚没款编号: ", normal);
                        PrintUtil.printText((Easy.getForfeitureDocumentNum()==null?"":Easy.getForfeitureDocumentNum()), normal_line);
                    }
                    if (strLength.length() <= 16) {
                        //换2行
                        PrintUtil.printText("\n\n                        "+(Easy.getRootDeptName()==null?"":Easy.getRootDeptName())+"\n                    " + Utils.GetUpperTime(Easy.getOccurredTime()) +
                                "\n    执法人员已向我出示《行政执法证》，告知了处罚的事实、理由和依据以及陈述申辩的权利。我对上述违法事实和处罚均无异议。\n                  当事人签字/盖章：___________" +
                                "\n                      " + Utils.GetUpperTime(Easy.getOccurredTime()) + "\n\n", normal);

                    } else if (strLength.length() <= 39) {
                        //换1行
                        PrintUtil.printText("\n                        "+(Easy.getRootDeptName()==null?"":Easy.getRootDeptName())+"\n                      " + Utils.GetUpperTime(Easy.getOccurredTime()) +
                                "\n    执法人员已向我出示《行政执法证》，告知了处罚的事实、理由和依据以及陈述申辩的权利。我对上述违法事实和处罚均无异议。\n                  当事人签字/盖章：___________" +
                                "\n                      " + Utils.GetUpperTime(Easy.getOccurredTime()) + "\n\n", normal);
                    } else {
                        //不换行
                        PrintUtil.printText("                          " + (Easy.getRootDeptName()==null?"":Easy.getRootDeptName()) + "\n                   " + Utils.GetUpperTime(Easy.getOccurredTime()) +
                                "\n    执法人员已向我出示《行政执法证》，告知了处罚的事实、理由和依据以及陈述申辩的权利。我对上述违法事实和处罚均无异议。\n                  当事人签字/盖章：___________" +
                                "\n                      " + Utils.GetUpperTime(Easy.getOccurredTime()) + "\n\n", normal);
                    }
                    PrintUtil.printToBlackMark();
                }
            }
        });
    }
    //打印暂扣物品决定书
    public static void printWitHold(Context context, final TempOraryBean sp){
        PrintUtil.init(context, new PrintUtil.PrintRunnable() {
            @Override
            public void run() throws Exception {
                if (sp.getCreateDate() == null) {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    sp.setCreateDate(simpleDateFormat.format(new Date()));
                }
                String createDate = sp.getCreateDate();
                String year = createDate.substring(0, 4);
                String month = createDate.substring(5, 7);
                String day = createDate.substring(8, 10);
                String hours = createDate.substring(11, 13);
                String minutes = createDate.substring(14, 16);
                // 当前时间
                Time time3 = new Time();
                time3.setToNow();
                int[] normal = new int[]{PrintUtil.HIGHERX01};
                int[] normal_line = new int[]{PrintUtil.HIGHERX01, PrintUtil.UNDERLINE, PrintUtil.BOLD};

                Thread.sleep(1000);
                //打印标签
                Goods goods;
                if (sp.getWithholdingItemsEntityList() == null) {
                    sp.setWithholdingItemsEntityList(new ArrayList<Goods>());
                }
                for (int i = 0; i < sp.getWithholdingItemsEntityList().size(); i++) {
                    goods = sp.getWithholdingItemsEntityList().get(i);
                    int cou = Integer.valueOf(goods.getItemAmount());
                    for (int j = 0; j < cou; j++) {

                        PrintUtil.printText(BaseApp.getUser().getCompanyName() + "\n", new int[]{PrintUtil.HIGHERX2, PrintUtil.ALIGNMIDDLE});
                        PrintUtil.printText("             物品查扣标记标牌", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                        StringBuffer sb = new StringBuffer();

                        PrintUtil.printText("\n  查扣编号：     ", normal);
                        PrintUtil.printText((j + 1) + "", normal);
                        // TableHost.blue.print("123213213", 4);
                        // sb.append("\n   时间：        "+"2012-12-12 12：22\n");
                        sb.append("\n   时间：        " + year + "年" + month + "月" + day
                                + "日" + "\n");
                        sb.append("   地点：        " + (sp.getLitigantAddress() == null ? "" : sp.getLitigantAddress()) + "\n");
                        sb.append("   当事人：      " + (sp.getLitigantName() == null ? "" : sp.getLitigantName()) + "\n");
                        sb.append("   物品名称： " + goods.getItemName() + "  数量：" + "1"
                                + "\n   单位：" + goods.getItemsNitValue());
                        PrintUtil.printText(sb.toString(), normal);
                        PrintUtil.printText("\n --------------------------------------------\n\n\n", normal);
                    }
                }
                PrintUtil.printToBlackMark();

                //打印标签完成

//                String str = "";
//                //判断有没有标识编号
//                for (int k = 0; k < sp.getGoodsList().size(); k++) {
//                    if (!sp.getGoodsList().get(k).getGoodsUnitCode().equals("") && sp.getGoodsList().get(k).getGoodsUnitCode() != null) {
//                        str = "（标识牌编号:" + sp.getGoodsList().get(k).getGoodsUnitCode() + "）";
//                        break;
//                    }
//                }
                for (int h = 0; h < 2; h++) {

                    PrintUtil.printText("\n\n" + BaseApp.getUser().getCompanyName(), new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                    PrintUtil.printText("\n             暂扣物品(工具)决定书", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                    PrintUtil.printText("\n                      编号： " + (sp.getNotificationNumber() == null ? "" : sp.getNotificationNumber()), normal);
                    PrintUtil.printText("\n    当事人：" + (sp.getLitigantName() == null ? "" : sp.getLitigantName())
                            + "  地址：" + (sp.getInvestigateLocation() == null ? "" : sp.getInvestigateLocation()), normal);
//				HomeActivity.blue.print("\n    地址：" + sp.getLocale(), 1);

                    PrintUtil.printText(
                            "\n    你(单位)" + (sp.getCreateDate() == null ? "" : Utils.GetUpperdate(sp.getCreateDate())) + "在" + (sp.getLitigantAddress() == null ? "" : sp.getLitigantAddress()) + "进行"
                                    + (sp.getItemAct() == null ? "" : sp.getItemAct()) + "的行为，涉嫌违反了"
                                    + (sp.getDutyName() == null ? "" : sp.getDutyName()) + "的规定。依据"
                                    + (sp.getGistName() == null ? "" : sp.getGistName())
                                    + "的规定，本机关决定对你（单位）的下列物品（工具）予以暂扣",
                            normal);
//                PrintUtil.printText(str, normal);
                    PrintUtil.printText("。", normal);
                    PrintUtil.printText("暂扣期限为30日", normal);
                    PrintUtil.printText("。\n\n", normal);


                    // 打印物品
                    PrintUtil.printText("编号     ", normal);
                    PrintUtil.printText("名称    ", normal);
                    PrintUtil.printText("单位  ", normal);
                    PrintUtil.printText("数量       ", normal);
                    PrintUtil.printText("备注\n", normal);
                    String name;// 物品名称
                    String name1;// 截取名称部分
                    String qty;// 大写的数量
                    int qtySize = 3;
                    String content;// 物品备注
                    int nameSize = 4; // 姓名一行的长度
                    int contentSize = 6;// 备注一行的长度
                    String space;
                    if (sp.getWithholdingItemsEntityList() == null) {
                        sp.setWithholdingItemsEntityList(new ArrayList<Goods>());
                    }
                    for (int i = 0; i < sp.getWithholdingItemsEntityList().size(); i++) {
                        goods = sp.getWithholdingItemsEntityList().get(i);
                        name = goods.getItemName();
                        qty = (ConvertNumber.numberToChinese(Integer.valueOf((goods.getItemAmount() == null ? "0" : goods.getItemAmount()))));
                        if (goods.getRemark() == null) {
                            goods.setRemark("");
                        }
                        content = goods.getRemark();
                        if (name.length() >= nameSize || content.length() >= contentSize) { // 判断姓名长度是否大于nameSize或者备注内容长度是否大于contentSize
                            // 判断姓名的长度 并且打印
                            if (name.length() <= nameSize) {
                                space = "";
                                for (int j = 0; j < nameSize - name.length(); j++) {
                                    space = space + "  ";
                                }
                                PrintUtil.printText("\n  " + (i + 1) + "      " + name
                                        + space, normal);
                            } else {
                                name1 = name.substring(0, nameSize);
                                PrintUtil.printText(
                                        "\n  " + (i + 1) + "      " + name1, normal);
                            }
                            // 打印单位和数量信息
                            if (qty.length() < qtySize) {
                                space = "";
                                for (int j = 0; j < qtySize - qty.length(); j++) {
                                    space = space + "  ";
                                }
                                PrintUtil.printText("  " + goods.getItemsNitValue() + "   "
                                        + qty + space, normal);
                            } else {
                                PrintUtil.printText("  " + goods.getItemsNitValue() + "   "
                                        + qty, normal);
                            }
                            // 判断备注的长度
                            if (content.length() <= contentSize) {
                                PrintUtil.printText("  " + content, normal);
                            } else {
                                PrintUtil.printText("  " + content.substring(0, contentSize), normal);
                            }
                            // 计算行数
                            int nameRow = name.length() % nameSize == 0 ? name.length()
                                    / nameSize : name.length() / nameSize + 1;
                            int contentRow = content.length() % contentSize == 0 ? content
                                    .length() / contentSize : content.length()
                                    / contentSize + 1;
                            // 使用行数多的数据为循环
                            if (nameRow > contentRow) {// 用姓名行数循环
                                for (int j = 1; j < nameRow; j++) {// 循环打印的行数（第J+1）行

                                    if (name.length() - j * nameSize > nameSize) {// 未打印的名称长度大于给定的名称列的长度
                                        // if(content.length()>j*contentSize){//未打印的备注长度大于给定的备注列的长度
                                        if (contentRow > j + 1) {// 备注行数大于当前行数
                                            PrintUtil.printText("\n         "
                                                    + name.substring(j * nameSize,
                                                    j * nameSize + nameSize)
                                                    + "\t\t"
                                                    + content.substring(j
                                                    * contentSize, j
                                                    * contentSize
                                                    + contentSize), normal);
                                        } else if (contentRow == (j + 1)) {// 备注行数等于当前的行数
                                            PrintUtil.printText("\n         "
                                                    + name.substring(j * nameSize,
                                                    j * nameSize + nameSize)
                                                    + "\t\t"
                                                    + content.substring(j
                                                    * contentSize), normal);
                                        } else if (contentRow < j + 1) {// 备注行数小于当前的行数
                                            PrintUtil.printText("\n         "
                                                            + name.substring(j * nameSize,
                                                    j * nameSize + nameSize),
                                                    normal);
                                        }

                                    } else {// 未打印的name长度不足给定的名称列的长度(备注长度已经完成)

                                        PrintUtil.printText(
                                                "\n         "
                                                        + name.substring(j * nameSize), normal);
                                    }
                                }
                            } else if (nameRow < contentRow) {// 备注行数多
                                for (int j = 1; j < contentRow; j++) {// 循环打印的行数（第J+1）行
                                    if (content.length() - j * contentSize > contentSize) {// 未打印的备注长度大于备注列的长度
                                        if (nameRow > j + 1) {// 名称行数大于当前行数
                                            PrintUtil.printText("\n         "
                                                    + name.substring(j * nameSize,
                                                    j * nameSize + nameSize)
                                                    + "\t\t"
                                                    + content.substring(j
                                                    * contentSize, j
                                                    * contentSize
                                                    + contentSize), normal);
                                        } else if (nameRow == (j + 1)) {// 名称行数等于当前的行数
                                            space = "";
                                            for (int k = 0; k < nameSize
                                                    - (name.length() - j * nameSize); k++) {
                                                space = space + "  ";
                                            }
                                            PrintUtil.printText(
                                                    "\n         "
                                                            + name.substring(j * nameSize)
                                                            + space
                                                            + "\t\t"
                                                            + content.substring(j
                                                            * contentSize, j
                                                            * contentSize
                                                            + contentSize), normal);
                                        } else if (nameRow < j + 1) {// 名称行数小于当前的行数
                                            PrintUtil.printText(
                                                    "\n\t\t\t\t"
                                                            + content.substring(j
                                                            * contentSize, j
                                                            * contentSize
                                                            + contentSize), normal);
                                        }
                                    } else {// 未打印的备注长度不足备注列的长度
                                        PrintUtil.printText("\n\t\t\t\t"
                                                        + content
                                                        .substring(j * contentSize),
                                                normal);
                                    }
                                }
                            } else {// 行数一样多
                                for (int j = 1; j < contentRow; j++) {// 循环打印的行数（第J+1）行
                                    if (name.length() - j * nameSize > nameSize) {// 未打印的备注长度大于备注列的长度
                                        PrintUtil.printText(
                                                "\n         "
                                                        + name.substring(j * nameSize, j
                                                        * nameSize + nameSize)
                                                        + "\t\t"
                                                        + content.substring(
                                                        j * contentSize, j
                                                                * contentSize
                                                                + contentSize), normal);
                                    } else {// 未打印的备注长度不足备注列的长度
                                        space = "";
                                        for (int k = 0; k < name.length() - j * nameSize; k++) {
                                            space = space + "  ";
                                            space += " ";
                                        }
                                        PrintUtil.printText("\n         "
                                                        + name.substring(j * nameSize)
                                                        + space
                                                        + "\t\t"
                                                        + content
                                                        .substring(j * contentSize),
                                                normal);
                                    }
                                }
                            }

                        } else {// 姓名长度和备注的长度都不大于一列的长度
                            space = "";
                            for (int j = 0; j < nameSize - name.length(); j++) {
                                space = space + "  ";
                            }
                            PrintUtil.printText("\n  " + (i + 1) + "      " + name
                                    + space + "   " + (goods.getItemsNitValue() == null ? "" : goods.getItemsNitValue()) + "       "
                                    + qty + "      " + content, normal);
                        }
                    }
                    PrintUtil.printText("\n", normal);


                    PrintUtil.printText("\n    请你（单位）于暂扣期满后 7 日内到", normal);

                    if (BaseApp.getUser().getDeptName().contains("机动中队")) {
                        PrintUtil.printText("___________________", normal);
                    } else {
                        PrintUtil.printText(sp.getDeptAddress(), normal_line);
                        PrintUtil.printText("接受处理，联系电话："+sp.getDeptPhone()+"。", normal);
                    }
                    //todo 这里要不要修改
                    PrintUtil.printText("如你（单位）不服本决定，", normal);
                    PrintUtil.printText("可以在接到本决定书之日起六十日内向昆山市人民政府申请行政复议;", normal);
                    PrintUtil.printText("也可以在六个月内直接向有管辖权的人民法院起诉。\n", normal);

                    PrintUtil.printText(
                            "\n\n\n执法人员（签名）："
                                    + BaseApp.getUser().getUserName() + " "
                                    + BaseApp.getPartner().getUserName() + " _____年___月___日", normal);
                    PrintUtil.printText("\n当事人（签名）：           _____年___月___日",
                            normal);
                    if (BaseApp.getUser().getCompanyName().length() > 17) {
                        PrintUtil.printText("\n              " + BaseApp.getUser().getCompanyName() + "\n", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD});
                    } else {
                        String str = "              ";
                        for (int i = 1; i <= (17 - BaseApp.getUser().getCompanyName().length()); i++) {
                            str += " ";
                        }
                        PrintUtil.printText("\n" + str + BaseApp.getUser().getCompanyName() + "\n", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD});
                    }
//                PrintUtil.printText("\n                   "+BaseApp.getUser().getCompanyName(), new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                    PrintUtil.printText("\n                           "
                            + time3.year + "年" + (time3.month + 1) + "月" + time3.monthDay + "日", normal);
                    PrintUtil.printToBlackMark();
                }
            }
        });

    }

    //打印先行登记
    public static void printAdvance(Context context, final TempOraryBean sp){
        PrintUtil.init(context, new PrintUtil.PrintRunnable() {
            @Override
            public void run() throws Exception {
                String createDate = sp.getCreateDate();
                String year = createDate.substring(0, 4);
                String month = createDate.substring(5, 7);
                String day = createDate.substring(8, 10);
                String hours = createDate.substring(11, 13);
                String minutes = createDate.substring(14, 16);
                // 当前时间
                Time time3 = new Time();
                time3.setToNow();
                int[] normal = new int[]{PrintUtil.HIGHERX01};
                int[] normal_line = new int[]{PrintUtil.HIGHERX01, PrintUtil.UNDERLINE, PrintUtil.BOLD};

                Thread.sleep(1000);
                //打印标签
                Goods goods;
                if (sp.getWithholdingItemsEntityList()==null){
                    sp.setWithholdingItemsEntityList(new ArrayList<Goods>());
                }
                for (int i = 0; i < sp.getWithholdingItemsEntityList().size(); i++) {
                    goods = sp.getWithholdingItemsEntityList().get(i);
                    int cou = Integer.valueOf(Integer.valueOf((goods.getItemAmount()==null?"":goods.getItemAmount())));
                    for (int j = 0; j < cou; j++) {

                        PrintUtil.printText("\n\n"+BaseApp.getUser().getCompanyName()+"\n",  new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                        PrintUtil.printText("             物品查扣标记标牌", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                        StringBuffer sb = new StringBuffer();

                        PrintUtil.printText("\n  查扣编号：     ", normal);
                        PrintUtil.printText((j + 1)+"", normal);
                        sb.append("\n   时间：        " + year + "年" + month + "月" + day
                                + "日" + "\n");
                        sb.append("   地点：        " + (sp.getLitigantAddress()==null?"":sp.getLitigantAddress()) + "\n");
                        sb.append("   当事人：      " + (sp.getLitigantName()==null?"":sp.getLitigantName()) + "\n");
                        sb.append("   物品名称： " + goods.getItemName() + "  数量：" + "1"
                                + "\n   单位：" + goods.getItemsNitValue());
                        PrintUtil.printText(sb.toString(), normal);
                        PrintUtil.printText("\n --------------------------------------------\n\n\n",normal);
                    }
                }
                PrintUtil.printToBlackMark();

                //打印标签完成

                //判断有没有标识编号
//                String str = "";
//                for (int k = 0; k < sp.getGoodsList().size(); k++) {
//                    if (!sp.getGoodsList().get(k).getGoodsUnitCode().equals("") && sp.getGoodsList().get(k).getGoodsUnitCode() != null) {
//                        str = "（标识牌编号:" + sp.getGoodsList().get(k).getGoodsUnitCode() + "）";
//                        break;
//                    }
//                }

                PrintUtil.printText("\n\n"+BaseApp.getUser().getCompanyName(),  new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                PrintUtil.printText("\n             证据先行登记保存通知书", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                PrintUtil.printText("\n                            编号："
                        + (sp.getNotificationNumber()==null?"":sp.getNotificationNumber()), normal);
                PrintUtil.printText("\n" + (sp.getLitigantName()==null?"":sp.getLitigantName()) + ":", normal);
                PrintUtil.printText("\n    经查，你(单位)于" + (sp.getCreateDate()==null?"":sp.getCreateDate()) + "在" + (sp.getInvestigateLocation()==null?"":sp.getInvestigateLocation())
                                + "进行", normal);
                PrintUtil.printText((sp.getItemAct()==null?"":sp.getItemAct()),normal);
                PrintUtil.printText("，已违反"
                                + (sp.getDutyName()==null?"":sp.getDutyName()) +
                                "的规定，本机关对你（单位）上述行为作进一步查处，现根据"
                                + "《中华人民共和国行政处罚法》第三十七条第二款"
                                + "的规定，对你（单位）的下述物品、证件，作为证据予以先行登记保存", normal);
//                PrintUtil.printText(str, normal);
                PrintUtil.printText("。登记保存期间，由本局执法人员负责妥善保管，任何单位和个人不得销毁或转移。\n\n",normal);

                // 打印物品
                PrintUtil.printText("编号     ", normal);
                PrintUtil.printText("名称    ", normal);
                PrintUtil.printText("单位  ", normal);
                PrintUtil.printText("数量       ", normal);
                PrintUtil.printText("备注\n", normal);
                String name;// 物品名称
                String name1;// 截取名称部分
                String qty;// 大写的数量
                int qtySize = 3;
                String content;// 物品备注
                int nameSize = 4; // 姓名一行的长度
                int contentSize = 6;// 备注一行的长度
                String space;

                if (sp.getWithholdingItemsEntityList()==null){
                    sp.setWithholdingItemsEntityList(new ArrayList<Goods>());
                }
                for (int i = 0; i < sp.getWithholdingItemsEntityList().size(); i++) {
                    goods = sp.getWithholdingItemsEntityList().get(i);
                    name = goods.getItemName();
                    qty = (ConvertNumber.numberToChinese(Integer.valueOf((goods.getItemAmount()==null?"0":goods.getItemAmount()))));
                    content = (goods.getRemark()==null?"":goods.getRemark());
                    if (name.length() >= nameSize || content.length() >= contentSize) { // 判断姓名长度是否大于nameSize或者备注内容长度是否大于contentSize
                        // 判断姓名的长度 并且打印
                        if (name.length() <= nameSize) {
                            space = "";
                            for (int j = 0; j < nameSize - name.length(); j++) {
                                space = space + "  ";
                            }
                            PrintUtil.printText("\n  " + (i + 1) + "      " + name
                                    + space, normal);
                        } else {
                            name1 = name.substring(0, nameSize);
                            PrintUtil.printText(
                                    "\n  " + (i + 1) + "      " + name1, normal);
                        }
                        // 打印单位和数量信息
                        if (qty.length() < qtySize) {
                            space = "";
                            for (int j = 0; j < qtySize - qty.length(); j++) {
                                space = space + "  ";
                            }
                            PrintUtil.printText("  " + goods.getItemsNitValue() + "   "
                                    + qty + space, normal);
                        } else {
                            PrintUtil.printText("  " + goods.getItemsNitValue() + "   "
                                    + qty, normal);
                        }
                        // 判断备注的长度
                        if (content.length() <= contentSize) {
                            PrintUtil.printText("  " + content, normal);
                        } else {
                            PrintUtil.printText("  " + content.substring(0, contentSize), normal);
                        }
                        // 计算行数
                        int nameRow = name.length() % nameSize == 0 ? name.length()
                                / nameSize : name.length() / nameSize + 1;
                        int contentRow = content.length() % contentSize == 0 ? content
                                .length() / contentSize : content.length()
                                / contentSize + 1;
                        // 使用行数多的数据为循环
                        if (nameRow > contentRow) {// 用姓名行数循环
                            for (int j = 1; j < nameRow; j++) {// 循环打印的行数（第J+1）行

                                if (name.length() - j * nameSize > nameSize) {// 未打印的名称长度大于给定的名称列的长度
                                    // if(content.length()>j*contentSize){//未打印的备注长度大于给定的备注列的长度
                                    if (contentRow > j + 1) {// 备注行数大于当前行数
                                        PrintUtil.printText("\n         "
                                                + name.substring(j * nameSize,
                                                j * nameSize + nameSize)
                                                + "\t\t"
                                                + content.substring(j
                                                * contentSize, j
                                                * contentSize
                                                + contentSize), normal);
                                    } else if (contentRow == (j + 1)) {// 备注行数等于当前的行数
                                        PrintUtil.printText("\n         "
                                                + name.substring(j * nameSize,
                                                j * nameSize + nameSize)
                                                + "\t\t"
                                                + content.substring(j
                                                * contentSize), normal);
                                    } else if (contentRow < j + 1) {// 备注行数小于当前的行数
                                        PrintUtil.printText("\n         "
                                                        + name.substring(j * nameSize,
                                                j * nameSize + nameSize),
                                                normal);
                                    }

                                } else {// 未打印的name长度不足给定的名称列的长度(备注长度已经完成)

                                    PrintUtil.printText(
                                            "\n         "
                                                    + name.substring(j * nameSize), normal);
                                }
                            }
                        } else if (nameRow < contentRow) {// 备注行数多
                            for (int j = 1; j < contentRow; j++) {// 循环打印的行数（第J+1）行
                                if (content.length() - j * contentSize > contentSize) {// 未打印的备注长度大于备注列的长度
                                    if (nameRow > j + 1) {// 名称行数大于当前行数
                                        PrintUtil.printText("\n         "
                                                + name.substring(j * nameSize,
                                                j * nameSize + nameSize)
                                                + "\t\t"
                                                + content.substring(j
                                                * contentSize, j
                                                * contentSize
                                                + contentSize), normal);
                                    } else if (nameRow == (j + 1)) {// 名称行数等于当前的行数
                                        space = "";
                                        for (int k = 0; k < nameSize
                                                - (name.length() - j * nameSize); k++) {
                                            space = space + "  ";
                                        }
                                        PrintUtil.printText(
                                                "\n         "
                                                        + name.substring(j * nameSize)
                                                        + space
                                                        + "\t\t"
                                                        + content.substring(j
                                                        * contentSize, j
                                                        * contentSize
                                                        + contentSize), normal);
                                    } else if (nameRow < j + 1) {// 名称行数小于当前的行数
                                        PrintUtil.printText(
                                                "\n\t\t\t\t"
                                                        + content.substring(j
                                                        * contentSize, j
                                                        * contentSize
                                                        + contentSize), normal);
                                    }
                                } else {// 未打印的备注长度不足备注列的长度
                                    PrintUtil.printText("\n\t\t\t\t"
                                                    + content
                                                    .substring(j * contentSize),
                                            normal);
                                }
                            }
                        } else {// 行数一样多
                            for (int j = 1; j < contentRow; j++) {// 循环打印的行数（第J+1）行
                                if (name.length() - j * nameSize > nameSize) {// 未打印的备注长度大于备注列的长度
                                    PrintUtil.printText(
                                            "\n         "
                                                    + name.substring(j * nameSize, j
                                                    * nameSize + nameSize)
                                                    + "\t\t"
                                                    + content.substring(
                                                    j * contentSize, j
                                                            * contentSize
                                                            + contentSize), normal);
                                } else {// 未打印的备注长度不足备注列的长度
                                    space = "";
                                    for (int k = 0; k < name.length() - j * nameSize; k++) {
                                        space = space + "  ";
                                        space += " ";
                                    }
                                    PrintUtil.printText("\n         "
                                                    + name.substring(j * nameSize)
                                                    + space
                                                    + "\t\t"
                                                    + content
                                                    .substring(j * contentSize),
                                            normal);
                                }
                            }
                        }

                    } else {// 姓名长度和备注的长度都不大于一列的长度
                        space = "";
                        for (int j = 0; j < nameSize - name.length(); j++) {
                            space = space + "  ";
                        }
                        PrintUtil.printText("\n  " + (i + 1) + "      " + name
                                + space + "   " + goods.getItemsNitValue() + "       "
                                + qty + "      " + content, normal);
                    }
                }
                PrintUtil.printText("\n", normal);
                PrintUtil.printText("\n\n上述证据本人已全部核对无误。", normal);
                PrintUtil.printText("\n           当事人:_______ _____年___月___日\n", normal);
                PrintUtil.printText("\n处理须知:请你（单位）于七日内持本通知书、有效身份证件及相关材料到", normal);
                PrintUtil.printText(BaseApp.getUser().getDepAddress(), normal_line);
                PrintUtil.printText(
                        "接受处理,联系电话:"
                                + BaseApp.getUser().getPhone(), normal);
                PrintUtil.printText(
                        "\n               执法人员（签名）："
                                + BaseApp.getUser().getUserName() + " "
                                + BaseApp.getPartner().getUserName(), normal);
                if (BaseApp.getUser().getCompanyName().length()>17)
                {
                    PrintUtil.printText("\n              " + BaseApp.getUser().getCompanyName() + "\n", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD});
                }else {
                    String str = "              ";
                    for (int i = 1; i <= (17 - BaseApp.getUser().getCompanyName().length()); i++) {
                        str += " ";
                    }
                    PrintUtil.printText("\n" + str + BaseApp.getUser().getCompanyName() + "\n", new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD});
                }
//                PrintUtil.printText("\n                   "+BaseApp.getUser().getCompanyName(), new int[]{PrintUtil.HIGHERX2, PrintUtil.BOLD, PrintUtil.ALIGNMIDDLE});
                PrintUtil.printText("\n                           "
                        + time3.year + "年" + (time3.month + 1) + "月"+time3.monthDay + "日", normal);
                PrintUtil.printToBlackMark();
            }
        });

    }
}
